package com.mynature.booking.database;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.mynature.booking.model.LogAndCreate;
import com.mynature.booking.model.Person;

public class CreateAccount extends JFrame {

	
	private static final long serialVersionUID = 3633046944137061910L;
	public static CreateAccount frame = new CreateAccount();
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;

	Person person = new Person();
	int i1;
	int i2;
	int i3;

	/**
	 * Create the frame.
	 */
	public CreateAccount() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblName = new JLabel("Name");
		lblName.setBounds(27, 22, 54, 15);
		contentPane.add(lblName);
		
		JLabel lblSex = new JLabel("Sex");
		lblSex.setBounds(27, 58, 54, 15);
		contentPane.add(lblSex);
		
		JLabel lblAge = new JLabel("Age");
		lblAge.setBounds(27, 97, 54, 15);
		contentPane.add(lblAge);
		
		JLabel lblPhone = new JLabel("Phone");
		lblPhone.setBounds(27, 136, 54, 15);
		contentPane.add(lblPhone);
		
		JLabel lblPersonalnumber = new JLabel("PersonalNumber");
		lblPersonalnumber.setBounds(27, 176, 84, 15);
		contentPane.add(lblPersonalnumber);
		
		textField = new JTextField();
		textField.setBounds(164, 19, 107, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		textField.getText();
		
		textField_1 = new JTextField();
		textField_1.setBounds(164, 55, 107, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		textField_1.getText();
		
		textField_2 = new JTextField();
		textField_2.setBounds(164, 94, 107, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		textField_2.getText();
		
		textField_3 = new JTextField();
		textField_3.setBounds(164, 133, 107, 21);
		contentPane.add(textField_3);
		textField_3.setColumns(10);
		textField_3.getText();
		
		textField_4 = new JTextField();
		textField_4.setBounds(164, 173, 107, 21);
		contentPane.add(textField_4);
		textField_4.setColumns(10);
		textField_4.getText();
		
		JButton btnConfirm = new JButton("Confirm");
		btnConfirm.setBounds(306, 54, 93, 23);
		contentPane.add(btnConfirm);
		btnConfirm.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				i1 = Integer.parseInt(textField_2.getText());
				i2 = Integer.parseInt(textField_3.getText());
				i3 = Integer.parseInt(textField_4.getText());
				person.setName(textField.getText());
				person.setSex(textField_1.getText());
				person.setAge(i1);
				person.setPhone(i2);
				person.setIdcard(i3);
				
				
				DatabaseManager.getInstance().insertPerson(person);
				setVisible(false);
			}
		});
		
		
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(306, 132, 93, 23);
		contentPane.add(btnBack);
		btnBack.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {

				setVisible(false);
				LogAndCreate.frame.setVisible(true);
			}
		});
	}
}
